package com.infore.common.model.dto.exchange;

import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;


@Data
public class TransformInfoDto implements Serializable {
    private static final long serialVersionUID = 8614450570678817217L;
    private String transformId;
    private String transformName;
    private String transformType;
    private String state;
    private String description;
    private String createTime;
    private String sourceId;
    private String sourceDatabaseId;
    private String sourceDatabaseName;
    private String sourceTable;
    private String sourceTableCn;
    private String sourceFields;
    private String sourceWhere;
    private String sourceIncrementCol;
    private String sourceIncrementType;
    private String sourceIncrementStartValue;
    private Integer sourceIncrementBeforeMinutes;
    private String sourceIncrementEndValue;
    private String sourceUrl;
    private String sourceUrlMethod;
    private String targetId;
    private String targetDatabaseId;
    private String targetDatabaseName;
    private String targetTable;
    private String targetTableCn;
    private String targetFields;
    private String targetIncrementCol;

    /**
     * 源数据列与目标数据列的映射关系
     */
    private List<MappingRelation> mappingRelations;


    public List<MappingRelation> getMappingRelations() {
        List<MappingRelation> list = new ArrayList<>();
        String[] sourceFields = this.sourceFields.split(",");
        String[] targetFields = this.targetFields.split(",");
        for (int i=0;i<sourceFields.length;i++){
            MappingRelation mappingRelation = new MappingRelation();
            mappingRelation.setSourceField(sourceFields[i]);
            mappingRelation.setTargetField(targetFields[i]);
            list.add(mappingRelation);
        }
        return list;
    }

    public void setMappingRelations(){

    }

    class MappingRelation{
        private String sourceField;
        private String targetField;

        public String getSourceField() {
            return sourceField;
        }

        public void setSourceField(String sourceField) {
            this.sourceField = sourceField;
        }

        public String getTargetField() {
            return targetField;
        }

        public void setTargetField(String targetField) {
            this.targetField = targetField;
        }
    }

}
